package org.kimoji.comment.dao;

import java.util.List;

import org.kimoji.entity.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class CommentDAO {

	private static final String COMMENT = "comment:";
	
	@Autowired
	private RedisTemplate<String, Comment> redisTemplate;
	
	public boolean saveComment(Comment comment){
		return redisTemplate.opsForList().rightPush(COMMENT+comment.getItemId(),comment)>0;
	}
	
	public List<Comment> getCommentsByItemId(String itemId,int start,int end){
		return redisTemplate.opsForList().range(COMMENT+itemId, start, end);
	}
	
	public int getCommentSizeByItemId(String itemId){
		int i = redisTemplate.opsForList().size(COMMENT+itemId).intValue();
		return i;
	}
	
}
